package org.example.controller;

import org.example.model.Attendance;
import org.example.service.AttendanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/attendance")
public class AttendanceController {

    @Autowired
    private AttendanceService attendanceService;

    // 根据考勤ID查询考勤记录
    @GetMapping("/{attendanceId}")
    public Attendance findAttendanceById(@PathVariable int attendanceId) {
        return attendanceService.findAttendanceById(attendanceId);
    }

    // 查询所有考勤记录
    @GetMapping("/all")
    public List<Attendance> queryAllAttendance() {
        return attendanceService.queryAllAttendance();
    }

    // 添加考勤记录
    @PostMapping("/add")
    public boolean addAttendance(@RequestBody Attendance attendance) {
        return attendanceService.addAttendance(attendance);
    }

    // 根据考勤ID更新考勤记录
    @PutMapping("/update")
    public boolean updateAttendance(@RequestBody Attendance attendance) {
        return attendanceService.updateAttendance(attendance);
    }

    // 根据考勤ID删除考勤记录
    @DeleteMapping("/{attendanceId}")
    public boolean deleteAttendance(@PathVariable int attendanceId) {
        return attendanceService.deleteAttendance(attendanceId);
    }

    // 批量删除考勤记录
    @DeleteMapping("/batchDelete")
    public boolean deleteAttendances(@RequestBody List<Integer> attendanceIds) {
        return attendanceService.deleteAttendances(attendanceIds);
    }

    // 按教师ID查询考勤记录
    @GetMapping("/teacher/{teacherId}")
    public List<Attendance> queryAttendanceByTeacherId(@PathVariable int teacherId) {
        return attendanceService.queryAttendanceByTeacherId(teacherId);
    }

    // 按日期范围查询考勤记录
    @PostMapping("/dateRange")
    public List<Attendance> queryAttendanceByDateRange(@RequestBody Map<String, Object> dateRange) {
        return attendanceService.queryAttendanceByDateRange(dateRange);
    }

    // 按考勤状态查询考勤记录
    @GetMapping("/status/{status}")
    public List<Attendance> queryAttendanceByStatus(@PathVariable String status) {
        return attendanceService.queryAttendanceByStatus(status);
    }
}